<?php
namespace app\admin\controller\user;

use app\admin\model\AdminRole;
use app\admin\service\sys\RoleService;
use app\admin\service\user\UserService;
use app\common\controller\AdminBase;
use app\common\model\User as UserModel;
use think\facade\Db;

/**
 * 用户操作控制器
 * 列表 添加 修改 删除等
*/
class User extends AdminBase{
    /**
     * 列表
     */
    public function user_list(){

        $parmas = reqDecode();//获取并参数解密

        $model = new UserModel();

        $list = $model->withSearch($this->searchFields($parmas),$this->searchData($parmas))->with('UserCate')
            ->field('id,avatar,state,username,nickname,cancel,uid,cate_id')
            ->order('id','desc')
            ->paginate($parmas['limit'], false)->toArray();
        return suc('成功',$list);
    }
    /**
     * 添加（客服） 编辑用户
    */
    public function user_add(){
       $user = reqDecode();//获取并参数解密
       if(!empty($user) && !empty($user['nickname'])){
          $res = UserService::saveOrEditUser($user,$this->admin->id);
          return  $res;
       }
       return suc('非法访问','',1);
    }
}
